package com.licheng.service.imp;

import com.licheng.mapper.DeptMapper;
import com.licheng.pojo.Dept;
import com.licheng.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImp implements DeptService {

    @Autowired
    private DeptMapper deptMapper;

    /**
     * 查询部门
     * @return
     */
    @Override
    public List<Dept> list(){
        List<Dept> deptList = deptMapper.selectAll();
        return deptList;
    }

    /**
     * 删除部门
     * @param id
     */
    @Override
    public void deleteDept(Integer id) {
        deptMapper.deleteDept(id);
    }

    /**
     * 添加部门
     * @param dept
     */
    @Override
    public void insertDept(Dept dept) {
        //添加基础属性
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insertDept(dept);
    }

    /**
     * 根据id查询部门
     * @param id
     * @return
     */
    @Override
    public Dept selectDeptById(Integer id) {
        Dept dept = deptMapper.selectDeptById(id);
        return dept;
    }

    /**
     * 修改部门
     * @param dept
     */
    @Override
    public void updateDept(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.updateDept(dept);
    }
}
